﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace SharePointBrowser.UserControls
{
    public class HyperlinkBox : TextBox
    {
        public bool IsValid
        {
            get
            {
                if (string.IsNullOrEmpty(Text) || Uri.IsWellFormedUriString(Text, UriKind.Absolute))
                {
                    BackColor = Color.White;
                    return true;
                }
                else
                {
                    BackColor = Color.LightPink;
                    return false;
                }
            }
        }

        public HyperlinkBox()
            : base()
        {
            Font = new Font(FontFamily.GenericSerif, 8F, FontStyle.Underline);
            ForeColor = Color.Blue;

            Validating += new CancelEventHandler(HyperlinkBox_Validating);
        }

        void HyperlinkBox_Validating(object sender, CancelEventArgs e)
        {
            e.Cancel = !IsValid;
        }
    }
}
